#include "petselection.h"

PetSelection::PetSelection(QWidget *parent) : QDialog(parent)
{
    setWindowTitle("选择宠物");
    catRadioButton = new QRadioButton("小猫", this);
    dogRadioButton = new QRadioButton("小狗", this);
    hamsterRadioButton = new QRadioButton("仓鼠", this);
    QLabel *nameLabel = new QLabel("给宠物起个可爱的名字吧：", this);
    nameLineEdit = new QLineEdit(this);
    confirmButton = new QPushButton("确认", this);
    connect(confirmButton, &QPushButton::clicked, this, &PetSelection::confirmClick);
    QVBoxLayout *radioLayout = new QVBoxLayout;
    radioLayout->addWidget(catRadioButton);
    radioLayout->addWidget(dogRadioButton);
    radioLayout->addWidget(hamsterRadioButton);
    QHBoxLayout *nameLayout = new QHBoxLayout;
    nameLayout->addWidget(nameLabel);
    nameLayout->addWidget(nameLineEdit);
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(radioLayout);
    mainLayout->addLayout(nameLayout);
    mainLayout->addWidget(confirmButton);
    setLayout(mainLayout);
}

QString PetSelection::getPetType() const
{
    return petType;
}

QString PetSelection::getPetName() const
{
    return petName;
}

void PetSelection::confirmClick()
{
    if (catRadioButton->isChecked())
    {
        petType = "小猫";
    }
    else if (dogRadioButton->isChecked())
    {
        petType = "小狗";
    }
    else if (hamsterRadioButton->isChecked())
    {

        petType = "仓鼠";
    }
    petName = nameLineEdit->text();

    accept();
}
